home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / Virtual User 1.0 / Example Libraries / TimeLib.vu < prev    next >
Text File  |  1991-01-25  |  3KB  |  103 lines

  1. #
  2. #    File:        TimeLib.vu
  3. #
  4. #    Contains:    Tasks that make it easier to work with time in VU.
  5. #
  6. #    Written by:    Sean Flynn
  7. #
  8. #    Copyright:    © 1990 by Apple Computer, Inc., all rights reserved.
  9. #
  10. #    Change History:
  11. #
  12. #        1/17/91       Rick         added task TimeElapsed
  13. #        1/25/91       naga         modified header and edited formats 
  14. #
  15. #    To Do:
  16. #
  17.  
  18.  
  19.  
  20. # *****************************************************************************************
  21. task WaitForTime( end_hour := 0, end_minute := 0, end_second := 0 )
  22. # WaitForTime task.  Wait until a specified time of day.
  23. begin
  24.     while match[time h:?h2 s:?s2] and
  25.             ( h2 / 100 <> end_hour  or
  26.               h2 mod 100 < end_minute or
  27.               s2 < end_second ) do;
  28. end;
  29.  
  30.  
  31. # *****************************************************************************************
  32. task PrintCurrentTime(print_date := true) begin
  33. # This task pretty prints the current time.  The format is as follows:
  34. #        <hour of day>:<minutes>:<seconds> <AM or PM>
  35. # It also takes one parameter that indicates whether the date should be printed.
  36. # If the actual parameter passed is a true value, the current date is also printed.
  37. # If no parameter is passed, the date is printed by default.
  38. # The format of the date is as follows:
  39. #        <month>/<day>/<year>
  40. #
  41.     match [time h:?hour s:?secs d:?day m:?month y:?year];
  42.     hour_of_day := hour / 100;
  43.     if(hour < 1200) begin # in AM
  44.         if(hour_of_day) print hour_of_day;
  45.         else print '12';
  46.         meridian := ' AM';
  47.     end;
  48.     else begin # in PM
  49.         if hour_of_day = 12 print hour_of_day;
  50.         else print hour_of_day - 12;
  51.         meridian := ' PM';
  52.     end;
  53.     print ':',(hour mod 100) / 10,(hour mod 10),':',secs;
  54.     print meridian;
  55.     if(print_date) begin
  56.         print " ",month,"/",day,"/",(year mod 100) / 10,(year mod 10);
  57.     end;
  58. end;
  59.  
  60.  
  61. (* Example Usage:
  62.     print_current_time(true);
  63. *)
  64.  
  65. # *****************************************************************************************
  66. Task    TimeElapsed( StartTime, StopTime )
  67. #    this task computes the difference between the start & stop time descriptors and 
  68. #    returns the result in a time desciptor. The dates are ignored.
  69. begin
  70.  
  71.     StartHour    := StartTime.h / 100;
  72.     StartMinute    := StartTime.h mod 100;
  73.     
  74.     StopHour    := StopTime.h / 100;
  75.     StopMinute    := StopTime.h mod 100;
  76.  
  77.             #####    Subtract seconds
  78.     if( StopTime.s < StartTime.s )        # must borrow from minutes column
  79.         begin
  80.         if( StopMinute = 0 )    # must borrow from hours column
  81.             begin
  82.                 StopHour := StopHour - 1;
  83.                 StopMinute := StopMinute + 60;
  84.             end;
  85.         StopMinute := StopMinute - 1;
  86.         StopTime.s := StopTime.s + 60;
  87.         end;
  88.     StopTime.s := StopTime.s - StartTime.s;
  89.  
  90.             #####    Subtract minutes
  91.     if( StopMinute < StartMinute )        # must borrow from hours column
  92.         begin
  93.         StopHour := StopHour - 1;
  94.         StopMinute := StopMinute + 60;
  95.         end;
  96.     StopMinute := StopMinute - StartMinute;
  97.  
  98.             #####    Subtract minutes
  99.     StopHour := StopHour - StartHour;
  100.         
  101.     return [ time y:0 m:0 d:0 h:(( StopHour * 100 ) + StopMinute) s:(StopTime.s) ];
  102. end;
  103.